package com.numericalmethod.algoquant.model.ralph2009.demo;


import javax.swing.JComponent;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.DefaultXYDataset;

import com.numericalmethod.algoquant.model.ralph2009.Ralph2009OptimizedPortfolio;

/**
 * Helper class to plot the results
 * @author Paul/Clement/Stephen
 *
 */
public class ResultsPlottingHelper {

	public static JComponent plotWeights(Ralph2009OptimizedPortfolio p, String title) {
		
		DefaultXYDataset dataset=new DefaultXYDataset();
		
		double[][] dynamicWeightSeries=new double [2][p.getDynamicWeightsCount()];
		for (int t=0;t<p.getDynamicWeightsCount();t++) {
			dynamicWeightSeries[0][t]=t;
			dynamicWeightSeries[1][t]=p.getDynamicWeightAt(t);
		}
		dataset.addSeries("Dynamic Weights", dynamicWeightSeries);
		
		double[][] myopicWeightSeries=new double [2][p.getMyopicWeightsCount()];
		for (int t=0;t<p.getDynamicWeightsCount();t++) {
			myopicWeightSeries[0][t]=t;
			myopicWeightSeries[1][t]=p.getMyopicWeightAt(t);
		}
		dataset.addSeries("Myopic Weights", myopicWeightSeries);
		
		
		JFreeChart chartObj=ChartFactory.createXYLineChart(
				title, "Time Step", "Weights", dataset, 
				PlotOrientation.VERTICAL, 
				true, true, false);

		return new ChartPanel(chartObj);
	}
		
}
